import { prisma } from "@/lib/prisma"
import { CategoryList } from "@/components/categories/category-list"
import { CategoryHeader } from "@/components/categories/category-header"
import { Metadata } from "next"

export const metadata: Metadata = {
  title: "分类管理 - 商场销售系统",
  description: "商品分类管理页面",
}

type SerializedCategory = {
  id: number
  name: string
  createdAt: string
  updatedAt: string
  _count: {
    products: number
  }
}

export default async function CategoriesPage() {
  const categories = await prisma.category.findMany({
    include: {
      _count: {
        select: { products: true }
      }
    },
    orderBy: {
      createdAt: 'desc'
    }
  })

  const serializedCategories: SerializedCategory[] = categories.map(category => ({
    ...category,
    createdAt: category.createdAt.toISOString(),
    updatedAt: category.updatedAt.toISOString()
  }))

  return (
    <div className="space-y-4 p-8">
      <CategoryHeader />
      <CategoryList categories={serializedCategories} />
    </div>
  )
} 